package com.aya.mapper.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Scope("prototype")
@Service
public class SimpleThread {
    Logger logger = LoggerFactory.getLogger(SimpleThread.class);

    public void simple() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("theradId:{}", Thread.currentThread().getId());
    }

    public void simpleException() {
        throw new RuntimeException("运行时异常");
    }

    @Async
    public void asyncSimpleException(String haha) {
        throw new RuntimeException("运行时异常");
    }

    @Async
    public void helloAsync() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("theradId:{}", Thread.currentThread().getId());
    }
}
